package com.job.gaoyue.day0702;

/**
 * @author ${高某}
 * @version 1.0
 * @since 2022-07-03 12:00:53
 */
public class mytool {
        //创建一个二分查找法
        public static int findtwo ( int[] arr, int key){
            int low=0,high=arr.length-1;//低下标 高下标
            int middle=-1;
            while (low<=high){
                middle = (low+high)/2;//中间下标
                //比数据
                if (arr[middle]==key){
                    break;
                }
                else
                {
                    if (arr[middle]>key){//high太大
                        high = middle-1;
                    }
                    else{//low  太小
                        low=middle+1;
                    }
                }

            }
            return middle;
        }
}